﻿namespace Bzstd.Entity;

/// <summary>
/// Json包装器
/// </summary>
[Serializable]
public class JsonWrapper
{
	/// <summary>
	/// 未知错误
	/// </summary>
	public static readonly JsonWrapper UnknownErrorResult = new() { Result = false, Message = "未知错误" };

	/// <summary>
	/// 无返回值
	/// </summary>
	public static readonly JsonWrapper VoidResult = new();

	/// <summary>
	/// 结果
	/// </summary>
	public bool Result { get; set; } = true;

	/// <summary>
	/// 数据
	/// </summary>
	public object Data { get; set; }

	/// <summary>
	/// 错误
	/// </summary>
	public string Error { get; set; }

	/// <summary>
	/// 信息
	/// </summary>
	public string Message { get; set; }

	/// <summary>
	/// 栈信息
	/// </summary>
	public string StackTrace { get; set; }

	public override string ToString()
	{
		return $"{nameof(Result)}: {Result}, {nameof(Data)}: {Data}, {nameof(Error)}: {Error}, {nameof(Message)}: {Message}, {nameof(StackTrace)}: {StackTrace}";
	}
}

/// <summary>
/// Json包装器
/// </summary>
/// <typeparam name="T"></typeparam>
[Serializable]
public class JsonWrapper<T> : JsonWrapper
{
	/// <summary>
	/// 数据
	/// </summary>
	public new T Data
	{
		get => (T) base.Data;
		set => base.Data = value;
	}
}
